package com.yh.homestay.controller;

import com.yh.homestay.common.HomeStayResult;
import com.yh.homestay.common.OwnerEditResult;
import com.yh.homestay.pojo.UserOwner;
import com.yh.homestay.service.UserOwnerService;
import com.yh.homestay.utils.QiNiuUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


@Controller
public class UserOwnerController {
    @Autowired
    private UserOwnerService ownerService;

    /**
     * @param
     * @return
     */
    @RequestMapping(value="/memberList", produces = "application/json; charset=utf-8")
    @ResponseBody
    public HomeStayResult selectAll(String ownerName, Integer page, Integer limit){
        HomeStayResult homeStayResult = ownerService.selectAll(ownerName,page,limit);
        return homeStayResult;
    }


    /**
     * @param userOwner
     * @return
     */
    @RequestMapping("/addOwner")
    public HomeStayResult addOwner(UserOwner userOwner){
        userOwner.setOwnerPhoto(QiNiuUtil.qiniu_img_url_pre+userOwner.getOwnerPhoto());
        userOwner.setOwnerIdcardA(QiNiuUtil.qiniu_img_url_pre+userOwner.getOwnerIdcardA());
        userOwner.setOwnerIdcardB(QiNiuUtil.qiniu_img_url_pre+userOwner.getOwnerIdcardB());
        HomeStayResult homeStayResult = ownerService.addOwner(userOwner);
        return homeStayResult;
    }

    /**
     *
     * @param
     * @return
     */
    @RequestMapping("/member-edit/{id}")
    @ResponseBody
    public HomeStayResult editMember(@PathVariable Integer id, String ownerName, String ownerPhone, String ownerPhoto, String ownerIdcardA, String ownerIdcardB, String ownerRoomIds){
        HomeStayResult update = ownerService.update(id, ownerName, ownerPhone, ownerPhoto, ownerIdcardA, ownerIdcardB, ownerRoomIds);
        return update;
    }

    /**
     * @param id
     * @return
     */
    @RequestMapping("/member-delete/{id}")
    @ResponseBody
    public HomeStayResult deleteById(@PathVariable Integer id){
        HomeStayResult delete = ownerService.delete(id);
        return delete;
    }

    @RequestMapping("/member-edit/selectOne/{id}")
    @ResponseBody
    public OwnerEditResult editOwner(@PathVariable Integer id){
        OwnerEditResult ownerEditResult = ownerService.selectOne(id);
        return ownerEditResult;
    }


    @RequestMapping("/member-deleteAll")
    @ResponseBody
    public HomeStayResult delectAll(@RequestParam List<Integer> ids){
        HomeStayResult homeStayResult = ownerService.delectAll(ids);
        return homeStayResult;
    }






}
